#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2007 Alex K (wtwf.com) All rights reserved.
# $Id: expandRss.py,v 1.35 2009-01-07 21:27:56 ark Exp $

import unittest

import expandrss

expandrss.image_proxy_url = 'http://proxy.example.com/'

class TextExpandRss(unittest.TestCase):

  def testFixRelativeUrls(self):
    tests = [("", "", ""),
             ("6” Classic", "", "6” Classic"),
             ("<img src=img.gif>",
              "http://example.com",
              "<img src=http://example.com/img.gif>"),
             ("""<img src="img.gif">""",
              "http://example.com",
              """<img src="http://example.com/img.gif">"""),
             ("<img src='img.gif'>",
              "http://example.com",
              "<img src='http://example.com/img.gif'>"),
             ("""<img src="img.gif">""",
              "http://example.com/base/foo.html",
              """<img src="http://example.com/base/img.gif">"""),
             ("""<img src="/bar/img.gif">""",
              "http://example.com/base/foo.html",
              """<img src="http://example.com/bar/img.gif">"""),
             ]

    for input, base, expected in tests:
      self.assertEqual(expected, expandrss.FixRelativeUrls(base, input))


  def testAddProxyToUrls(self):
    tests = [("", ""),
             ("<img src=http://example.com/img.gif>",
              "<img src=http://proxy.example.com/http://example.com/img.gif>"),
             ]

    for input, expected in tests:
      self.assertEqual(expected, expandrss.AddProxyToUrls(input))


if __name__ == '__main__':
    unittest.main()
